package com.itcast.demo_one

import android.os.Bundle
import android.widget.Toast
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.itcast.demo_one.fragment.DetailFragment
import com.itcast.demo_one.fragment.ListFragment

class MainActivity : AppCompatActivity(), ListFragment.onItemClickListener {
    override fun onCreate(savedInstanceState: Bundle?) {
        // 调用父类的onCreate方法，确保初始化完成
        super.onCreate(savedInstanceState)

        // 启用边缘到边缘显示模式，让内容可以延伸到系统栏区域
        enableEdgeToEdge()

        // 设置Activity的布局文件
        setContentView(R.layout.activity_main)

        // 加载Fragment
        if(savedInstanceState == null){
            supportFragmentManager.beginTransaction()
                .add(R.id.fragment_container, ListFragment())
                .commit()
        }
    }
    override fun onItemClick(position: Int) {
        // Toast.makeText(this, "点击了第 $position 项", Toast.LENGTH_SHORT).show()
        supportFragmentManager.beginTransaction()
            .replace(R.id.fragment_container, DetailFragment())
            .addToBackStack(null)
            .commit()
    }
}